﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WWDemon.Log;

namespace WWDemon.Client
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.ThreadException += Form1_UIThreadException;

            //始终将异常传送到 System.Windows.Forms.Application.ThreadException 处理程序。忽略应用程序配置文件
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            // 当某个异常未被捕获时出现.   
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        // 线程异常.  
        private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            LogHelper.Log(LogDefine.LogError, t.Exception);

            //MessageBox.Show("程序遇到未知异常：" + t.Exception.StackTrace, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
        }

        // 主进程异常.   
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = (Exception)e.ExceptionObject;

            LogHelper.Log(LogDefine.LogError, e);

            //MessageBox.Show("程序遇到未知异常：" + ex.StackTrace, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
        }
    }
}
